SeasonToolbar = function(Option){
	var this_bar = this;
	var panel = Option.panel; //所属panel(grid)
	
	var year_cache;
	
	this.init = function(){
		var date = new Date();
		year_cache = year_cache || date.getFullYear();
		var start = year_cache+"-01-01";
		var end = (parseInt(year_cache)+1)+"-01-01";
		findAllBySeason(start, end);
		this_bar.total.toggle(true);
	}
	
	var findAllBySeason = function(start, end){
		panel.el.mask("读取中 ...","x-mask-loading");
		Ext.Ajax.request({
			url : Option.url, //所属panel加载数据的url
			params : {"start": start, "end": end, "type":Option.type},
			success : function(resp){
				var array = Ext.decode(resp.responseText);
				panel.store.loadData(array);
				panel.el.unmask();
				if(Option.afterLoad!==undefined)
					Option.afterLoad(array); //所属panel加载完后执行的动作
			}
		});
	}
	
	var toggleAction = function(btn, state){
		if(state===true){
			var start,end;
			var year = this_bar.year.getRawValue()
			if(btn === this_bar.oneS){
				start = year+"-01-01";
				end = year+"-04-01";
			}else if(btn === this_bar.twoS){
				start = year+"-04-01";
				end = year+"-07-01";
			}else if(btn === this_bar.threeS){
				start = year+"-07-01";
				end = year+"-10-01";
			}else if(btn === this_bar.fourS){
				start = year+"-10-01";
				end = (parseInt(year)+1)+"-01-01";
			}else if(btn === this_bar.total){
				start = year+"-01-01";
				end = (parseInt(year)+1)+"-01-01";
			}
			findAllBySeason(start, end);
		}
	};
	SeasonToolbar.superclass.constructor.call(this, {
		items : [{
			ref : "total",
			text : "全年",
			enableToggle: true,
			toggleGroup : "season",
			pressed: true,
			toggleHandler: toggleAction
		},'-',{
			ref : "oneS",
			text : "第一季度(1月-3月)",
			enableToggle: true,
			toggleGroup : "season",
			toggleHandler: toggleAction
		},'-',{
			ref : "twoS",
			text : "第二季度(4月-6月)",
			enableToggle: true,
			toggleGroup : "season",
			toggleHandler: toggleAction
		},'-',{
			ref : "threeS",
			text : "第三季度(7月-9月)",
			enableToggle: true,
			toggleGroup : "season",
			toggleHandler: toggleAction
		},'-',{
			ref : "fourS",
			text : "第四季度(10月-12月)",
			enableToggle: true,
			toggleGroup : "season",
			toggleHandler: toggleAction
		},'-','->',"选择年份:",{
			ref : "year",
			xtype : "combo",
			editable : false,
			typeAhead: true,
		    triggerAction: 'all',
		    lazyRender:true,
		    forceSelection : true,
		    mode: 'local',
		    value : 2012,
		    width : 70,
		    store: new Ext.data.JsonStore({
		        fields: ["year"],
		        data : [{year:2011},{year:2012}]
		    }),
		    valueField: "year",
		    displayField: "year",
		    listeners : {
		    	select : function(combo, rec, i){
		    		year_cache = rec.get("year");
		    		this_bar.init();
		    	}
		    }
		}]
	});
};
Ext.extend(SeasonToolbar, Ext.Toolbar);